/**
 *Copyright (c) 2024 watereyes
 * safetymanagement is licensed under Mulan PubL v2.
 * You can use this software according to the terms and conditions of the Mulan
 * PubL v2.
 * You may obtain a copy of Mulan PubL v2 at:
 *          http://license.coscl.org.cn/MulanPubL-2.0
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PubL v2 for more details.
 */
package com.koron.purpose.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.koron.purpose.domain.SafetyOrgStaff;

public interface SafetyOrgStaffMapper {
	
	@Insert("insert into safety_org_staff(id,add_user,add_user_name,add_time,update_user,update_user_name,update_time,"
			+ "staff_code,staff_name,dept_code,dept_name,phone,note,org_role,isleader,serial,org_id)"
			+ " values(#{id},#{addUser},#{addUserName},#{addTime},#{updateUser},#{updateUserName},#{updateTime},"
			+ "#{staffCode},#{staffName},#{deptCode},#{deptName},#{phone},#{note},#{orgRole},#{isleader},#{serial},#{orgId})")
	Integer insert(SafetyOrgStaff bean);
	
	@Update("update safety_org_staff set update_user=#{updateUser},update_user_name=#{updateUserName},update_time=#{updateTime},"
			+ "staff_code=#{staffCode},staff_name=#{staffName},dept_code=#{deptCode},dept_name=#{deptName},phone=#{phone},"
			+ "note=#{note},org_role=#{orgRole},isleader=#{isleader},serial=#{serial} where id=#{id}")
	Integer update(SafetyOrgStaff bean);
	
	@Delete("delete from safety_org_staff where id=#{id}")
	Integer delete(@Param("id") String id);
	
	@Select("<script>"
			+ "select * from safety_org_staff where org_id=#{orgId}  <if test='name !=null'> and staff_name like concat('%',#{name},'%')</if>"
			+ "<if test='keyword !=null'> and (staff_name like concat('%',#{keyword},'%') or dept_name like concat('%',#{keyword},'%') or note like concat('%',#{keyword},'%') or org_role like concat('%',#{keyword},'%') )</if>"
			+ "order by serial"
			+ "<if test='start !=null'> limit #{start},#{row}</if>"
			+ "</script>")
	List<SafetyOrgStaff> query(@Param("name") String name,@Param("orgId") String orgId,@Param("start") Integer start,@Param("row") Integer row,@Param("keyword") String keyword);

	@Select("<script>"
			+"select count(*) from safety_org_staff where org_id=#{orgId} and staff_name like #{name}"
			+ "<if test='keyword !=null'> and (staff_name like concat('%',#{keyword},'%') or dept_name like concat('%',#{keyword},'%') or note like concat('%',#{keyword},'%') or org_role like concat('%',#{keyword},'%'))</if>"
			+ "</script>")
	Integer count(@Param("name") String name,@Param("orgId") String orgId,@Param("keyword") String keyword);
	
	@Select("select count(*) from safety_org_staff where staff_code=#{staffCode} and org_id=#{orgId}")
	Integer addVerification(@Param("staffCode") String staffCode,@Param("orgId") String orgId);
	
	@Select("select count(*) from safety_org_staff where staff_code=#{staffCode} and org_id=#{orgId} and id!=#{id}")
	Integer updateVerification(@Param("staffCode") String staffCode,@Param("orgId") String orgId,@Param("id") String id);
	
	@Select("select * from safety_org_staff where id=#{id}")
	SafetyOrgStaff queryById(@Param("id") String id);
}
